package com.kfm.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kfm.hotel.domain.SysDict;
import com.kfm.hotel.mapper.SysDictMapper;
import com.kfm.hotel.service.SysDictService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 10854
* @description 针对表【sys_dict】的数据库操作Service实现
* @createDate 2023-06-05 09:59:12
*/
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict>
    implements SysDictService{

    @Override
    public PageInfo<SysDict> list(SysDict sysDict, Integer page, Integer limit) {
        // 查询条件
        QueryWrapper<SysDict> wrapper = new QueryWrapper<>();
//        if (user.getUsername() != null && !user.getUsername().equals("")) {
//            wrapper.like("username", user.getUsername());
//        }

        wrapper.eq("is_del", 0);

        // 查询并封装成 PageInfo 对象
        // 分页
        PageHelper.startPage(page, limit);
        List<SysDict> sysDicts = getBaseMapper().selectList(wrapper);
        PageInfo<SysDict> pageInfo = new PageInfo<>(sysDicts);
        return pageInfo;
    }

    @Override
    public List<SysDict> getByType(int type) {
        QueryWrapper<SysDict> wrapper = new QueryWrapper<>();
        wrapper.eq("type", type);
        wrapper.eq("is_del", 0);
        // 排序
        wrapper.orderByAsc("sort");

        return list(wrapper);
    }
}




